package com.longtop.leaning.util;

import java.util.Random;

public class StringUtils {
	   static Random r = new Random();
	   static String ssource ="0123456789";
	   static char[] src = ssource.toCharArray();
	   //产生随机字符串4位数字
	   public static String randString (int length){
	        char[] buf = new char[length];
	        int rnd;
	        for(int i=0;i<length;i++){
	            rnd = Math.abs(r.nextInt()) % src.length;
	            buf[i] = src[rnd];
	        }
	        return new String(buf);
	   }
	   
		// 字符串替换
		public static final String replace(String line, String oldString, String newString) 
	    { 
	        if (line == null) { 
	            return null; 
	        } 
	        int i=0; 
	        if ( ( i=line.indexOf( oldString, i ) ) >= 0 ) { 
	            char [] line2 = line.toCharArray(); 
	            char [] newString2 = newString.toCharArray(); 
	            int oLength = oldString.length(); 
	            StringBuffer buf = new StringBuffer(line2.length); 
	            buf.append(line2, 0, i).append(newString2); 
	            i += oLength; 
	            int j = i; 
	            while( ( i=line.indexOf( oldString, i ) ) > 0 ) { 
	                buf.append(line2, j, i-j).append(newString2); 
	                i += oLength; 
	                j = i; 
	            } 
	            buf.append(line2, j, line2.length - j); 
	            return buf.toString(); 
	        } 
	        return line; 
	    }
		
		/*
		 * 判断某字串是否都为
		 * 数字组成
		 * by haicao
		 * 2008-12-2
		 */
		public static boolean isNumber(String str) {
			for (int i = 0; i < str.length(); i ++) {
				char c = str.charAt(i);
				if (!(c >= '0' && c <= '9'))
					return false;
			}
			return true;
		}
		
		/*
		 * 判断字串是否为空
		 * by haicao
		 * 2008-12-2
		 */
		public static boolean isEmpty(String str) {
			if (str == null || str.trim().equals(""))
				return true;
			return false;
		}

		
		public static void main(String[] args) {
			
		}
}
